//
//  SettingViewController.m
//  苏州银行
//
//  Created by rimi on 15/8/20.
//  Copyright (c) 2015年 IOS. All rights reserved.
//

#import "SZYHSettingViewController.h"
#import "SZYHSettingDetailViewController.h"
#import "Masonry.h"
#import "Config.h"
@interface SZYHSettingViewController ()<UIScrollViewDelegate, UITextFieldDelegate>

@property (strong, nonatomic) IBOutlet UIView *settingImageView;
@property (nonatomic, strong) UIView       *backImage;
@property (nonatomic, assign) NSInteger     currentIndex;
@property (nonatomic, strong) UIPageControl *pageControl;

@end

@implementation SZYHSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeUserInterface];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboarWillHiden:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)initializeUserInterface
{
    _backImage = [[UIView alloc]initWithFrame:self.view.bounds];
    _backImage.backgroundColor = [UIColor blackColor];
    _backImage.alpha = 0.7;
    [self.view insertSubview:_backImage atIndex:0];

}

- (IBAction)closeSettingView:(id)sender {
    _backImage.alpha = 0;
    [self.view removeFromSuperview];
}
- (IBAction)detailContent:(UIButton *)sender {
    UIStoryboard *changeSotory = [UIStoryboard storyboardWithName:@"Setting" bundle:nil];
    SZYHSettingDetailViewController *SZYHSettingDetailVC = [[SZYHSettingDetailViewController alloc]init];
    SZYHSettingDetailVC = [changeSotory instantiateViewControllerWithIdentifier:@"SETTINGDETAIL"];
    
    [self addChildViewController:SZYHSettingDetailVC];
    [self.view addSubview:SZYHSettingDetailVC.view];
    UIImageView *aboutBank = [[UIImageView alloc]initWithImage:IMGNAME(@"关于我行_内容")];
    if (sender.tag == 101) {
        aboutBank.frame = CGRectMake(0, 0, SZYHSettingDetailVC.settingDetailScrollView.frame.size.width, SZYHSettingDetailVC.settingDetailScrollView.frame.size.height + 200);
        SZYHSettingDetailVC.settingDetailScrollView.contentSize = CGSizeMake(0, aboutBank.frame.size.height);
        [SZYHSettingDetailVC.settingDetailScrollView addSubview:aboutBank];
        SZYHSettingDetailVC.settingDetaiLabel.text = @"【关于我行】";
    }else if (sender.tag == 102) {
        SZYHSettingDetailVC.settingDetaiLabel.text = @"【版本信息】";
        
        aboutBank.image = IMGNAME(@"用户中心_版本信息_苏州银行");
        aboutBank.frame = CGRectMake(SZYHSettingDetailVC.settingDetailScrollView.frame.size.width / 2 - 150, 0, SZYHSettingDetailVC.settingDetailScrollView.frame.size.width - 500, SZYHSettingDetailVC.settingDetailScrollView.frame.size.height - 200);
        [SZYHSettingDetailVC.settingDetailScrollView addSubview:aboutBank];
    }else if (sender.tag == 103) {
        NSArray *imageArray = @[@"用户指南_1.png", @"用户指南_2.png", @"用户指南_3.png", @"用户指南_4.png", @"用户指南_5.png"];
        SZYHSettingDetailVC.settingDetailScrollView.contentSize = CGSizeMake((SZYHSettingDetailVC.settingDetailScrollView.frame.size.width) * imageArray.count, 0);
        SZYHSettingDetailVC.settingDetailScrollView.delegate  =self;
        for (int i = 0; i < imageArray.count; i ++) {
            UIImageView *aboutBank = [[UIImageView alloc]initWithImage:IMGNAME(imageArray[i])];
            aboutBank.frame = CGRectMake(SZYHSettingDetailVC.settingDetailScrollView.frame.size.width * i + 20, 0, SZYHSettingDetailVC.settingDetailScrollView.frame.size.width - 20, SZYHSettingDetailVC.settingDetailScrollView.frame.size.height);
            [SZYHSettingDetailVC.settingDetailScrollView addSubview:aboutBank];
        }
        SZYHSettingDetailVC.settingDetailScrollView.pagingEnabled = YES;
        SZYHSettingDetailVC.settingDetailScrollView.contentOffset = CGPointMake(0, 0);
        _currentIndex = 0;
        _pageControl = [[UIPageControl alloc]init];
        _pageControl.bounds = CGRectMake(0, 0, 100, 100);
        _pageControl.center = CGPointMake(self.view.center.x, self.view.center.y + 300);
        _pageControl.pageIndicatorTintColor = [UIColor colorWithWhite:0.800 alpha:1.000];
        _pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
        _pageControl.numberOfPages = imageArray.count;
        [self.view addSubview:_pageControl];
        SZYHSettingDetailVC.settingDetaiLabel.text = @"【使用指南】";
    }else {
        SZYHSettingDetailVC.settingDetaiLabel.text = @"【用户反馈】";
        aboutBank.image = IMGNAME(@"用户反馈_背景");
        aboutBank.frame = CGRectMake(0, 20, SZYHSettingDetailVC.settingDetailScrollView.frame.size.width, SZYHSettingDetailVC.settingDetailScrollView.frame.size.height - 150);
        [SZYHSettingDetailVC.settingDetailScrollView addSubview:aboutBank];
        UILabel *email = [[UILabel alloc]initWithFrame:CGRectMake(5, aboutBank.frame.size.height - 80, 100, 50)];
        email.text = @"您的邮箱";
        email.font = [UIFont systemFontOfSize:20];
        [aboutBank addSubview:email];
        UITextField *emailText = [[UITextField alloc]initWithFrame:CGRectMake(205, 550, 300, 50)];
        emailText.backgroundColor = [UIColor blackColor];
        emailText.delegate = self;
        [self.view addSubview:emailText];
    }
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSInteger current = scrollView.contentOffset.x / 815;
    _pageControl.currentPage = current;
}

- (void)keyboardWillShow:(NSNotification *)notification
{
    
}



@end
